package effectiveJava.myEnum;

/**
 * Created by dycong on 2017/9/4.
 */
public enum PayrollDay {
    MONDAY,
    TUESDAY,
    WEDNESDAY,
    THURSDAY,
    FRIDAY,
    SATURDAY,
    SUNDAY;

    private static final int HOURS_PER_SHIFT = 8;

    public double pay(double hoursWorked, double payRate) {
        double base = hoursWorked * payRate;
        double overtimePay = 0;
        /*this*/
        switch (this) {
            case SATURDAY:
            case SUNDAY:
                overtimePay = hoursWorked * payRate / 2;
                break;
            default:
                overtimePay = hoursWorked <= HOURS_PER_SHIFT ? 0 : (hoursWorked - HOURS_PER_SHIFT) / 2;
                break;
        }
        return base + overtimePay;
    }

/*todo 添加新的节假日时，如果没有修改switch语句，工资会算错*/
}
